package com.lovo.order.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lovo.common.result.GlobalHandleException;
import com.lovo.common.result.ResponseResult;
import com.lovo.common.result.ResultCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ResponseResult
public class IndexControler {
    @ResponseResult
    @GetMapping("/message1")
    public Object message1(){
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "message1";
    }
    int i = 0;
    @GetMapping("/message2")
    public Object message2() throws GlobalHandleException {
        i++;
        if(i % 3 == 0){
            throw new GlobalHandleException(ResultCode.SERVER_UNKNOW_ERROR);
        }
        return "message2";
    }
    @GetMapping("/message3")
    @SentinelResource("message3")
    public Object message3(String name,Integer age){
        System.out.println("name:"+name+"\nage:"+age);
        return "message3";
    }
}
